package com.wechat.service.account.starter.customMenu;

import com.alibaba.fastjson.JSONObject;
import com.wechat.service.account.starter.AccessTokenService;
import com.wechat.service.account.starter.BaseWechatService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

/**
 * @author： ygl
 * @date： 2019/07/10
 * @Description：
 * 自定义菜单删除接口
 * 调用此接口会删除默认菜单及全部个性化菜单
 */
@Slf4j
@Service
public class MenuDeleteService extends BaseWechatService {


    public boolean deleteMenu(){
        ResponseEntity<JSONObject> responseEntity = restTemplate.getForEntity(buildDeleteMenuUrl(), JSONObject.class);
        JSONObject body = responseEntity.getBody();
        log.info("*******删除自定义菜单结果:{}******",JSONObject.toJSONString(body));
        if (0 == body.getInteger("errcode")) {
            return true;
        }
        return false;
    }

    public String buildDeleteMenuUrl(){
        return "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token="+accessTokenService.getAccessToken();
    }
}
